package com.testjpa.web;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.Map;

/**
 * 作者: LCG
 * 日期: 2020/5/19 11:40
 * 描述:
 */
@RestController
public class TestHystrixController {

    @Autowired
    private RestTemplate restTemplate;

    @RequestMapping("test03/{id}")
    @HystrixCommand(fallbackMethod = "test04")
    public String test03(@PathVariable("id") String id){

        Map<String,Object> map=new HashMap<>();
        map.put("ok","===hystrix===");
        map.put("id",id);
        String reult = restTemplate.postForObject("http://localhost:10052/test02", map, String.class);

        return reult;
    }

    public String test04(@PathVariable("id") String id){
        return "出错了"+id;
    }

}
